﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.iRods.Common;
using System.IO;

namespace Renci.iRods.Packets
{
    //#define OpenedDataObjInp_PI "int l1descInx; int len; int whence; int oprType; double offset; double bytesWritten; struct KeyValPair_PI;"
    [Packet("OpenedDataObjInp_PI")]
    internal class OpenedDataObjectInputPacket : Packet
    {
        private IDictionary<string, string> _keyValues = new Dictionary<string, string>();

        //for read, write, close
        [PacketField("l1descInx", 0, DataTypes.Int)]
        public int Handle { get; set; }

        //length of operation for read, write 
        [PacketField("len", 1, DataTypes.Int)]
        public int Length { get; set; }

        //used for lseek 
        [PacketField("whence", 2, DataTypes.Int)]
        public SeekOrigin SeekOrigin { get; set; }

        [PacketField("oprType", 3, DataTypes.Int)]
        public OperationTypes OperationType { get; set; }

        [PacketField("offset", 4, DataTypes.Int)]
        public double Offset { get; set; }

        //for close
        [PacketField("bytesWritten", 5, DataTypes.Int)]
        public double BytesWritten { get; set; }

        //include chksum flag and value
        [PacketField("KeyValPair_PI", 6, DataTypes.Packet)]
        public KeyValuePairPacket KeyValues
        {
            get
            {
                return new KeyValuePairPacket(this._keyValues);
            }
            set
            {

            }
        }

        public void AddKey(string key, string value)
        {
            this._keyValues.Add(key, value);
        }

    }
}
